package com.content.view.Frame.MainPanel.MPHome
{
	import com.clerkq.CoverFlow.CoverFlow;
	import com.content.model.Collection.ItemGroup;
	import com.content.model.Collection.ItemVO;
	import com.content.model.LoadedAssets.FontProxy;
	import com.content.model.LoadedAssets.SkinProxy;
	import com.content.model.OnlineRes.OnlineResHomeVO;
	import com.content.view.Frame.MainPanel.SPBase;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.ProgressEvent;
	
	public class SPShowCase extends SPBase
	{
		private var _showContainer:Sprite;
		private var _coverFlow:CoverFlow;
		
		public function SPShowCase()
		{
			super(this);
			
			_showContainer = new Sprite();
			addChild(_showContainer);
			
//			_coverFlow = new CoverFlow(940, 361);
			_coverFlow = new CoverFlow(5, 5);
			_showContainer.addChild(_coverFlow);
			_coverFlow.coverBackgroundColor = 0xffffff;
			_coverFlow.fontName = FontProxy.FONT_YAHEI;
			_coverFlow.fontColor = 0x000000;
			_coverFlow.fontSize = 18;
			_coverFlow.horizontalSpacing = 70;
			_coverFlow.verticalOffset = 70;
			_coverFlow.centerMargin = 100;
			
			_coverFlow.addEventListener(Event.COMPLETE, OnCoverFlowLoaded);
			_coverFlow.addEventListener(ProgressEvent.PROGRESS, OnCoverFlowProgress);
			_coverFlow.addEventListener(MouseEvent.DOUBLE_CLICK, OnCoverFlowDoubleClick);
		}
		
		private function RemoveAllItem():void{
			/*var nItem:RecommendItem;
			while(_recommandContainer.numChildren > 0){
				nItem = _recommandContainer.removeChildAt(0) as RecommendItem;
				nItem.Dispose();
			}*/
		}
		
		override public function SetLayout(areaWidth:int, areaHeight:int):void{
			super.SetLayout(areaWidth, areaHeight);
			
			_coverFlow.width = areaWidth;
			_coverFlow.height = areaHeight;
		}
		
		public function Refresh(itemGroup:ItemGroup):void{
			RemoveAllItem();
			
			_coverFlow.SetContent(itemGroup);
			_coverFlow.selectedIndex = int(itemGroup.Length/2);
			
			SetLayout(_areaW, _areaH);	// 得到数据后，手动重排内容
		}
		
		/* Event Handler
		 * ------------------------------------------------- */
		private function OnCoverFlowProgress(e:ProgressEvent):void {
			//trace("Coverflow progress: " + e.bytesLoaded + " / " + e.bytesTotal);
		}
		
		private function OnCoverFlowLoaded(e:Event):void {
			//trace("Coverflow loaded and ready to go.");
			//coverFlow.horizontalSpacing = 100;
			//coverFlow.centerMargin = 75;
			//coverFlow.backRowDepth = 300;
			//coverFlow.backRowAngle = 75;
			//coverFlow.verticalOffset = 50;
			
			/*coverFlow.fontName = "Courier";
			coverFlow.fontSize = 24;
			coverFlow.fontColor = 0xff0000;*/
			//coverFlow.height -= 50;
			//setTimeout(coverFlow.load, 1000, "coverFlowImages.xml");
		}
		
		private function OnCoverFlowDoubleClick(e:MouseEvent):void {
			//navigateToURL(new URLRequest(e.target.data.link));
		}
		
		override public function Dispose():void
		{
			_coverFlow.removeEventListener(Event.COMPLETE, OnCoverFlowLoaded);
			_coverFlow.removeEventListener(ProgressEvent.PROGRESS, OnCoverFlowProgress);
			_coverFlow.removeEventListener(MouseEvent.DOUBLE_CLICK, OnCoverFlowDoubleClick);
		}
	}
}